package com.ycd.gis.controller;

import java.util.List;

import com.ycd.common.core.domain.entity.SysUser;
import com.ycd.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ycd.common.annotation.Log;
import com.ycd.common.enums.BusinessType;
import com.ycd.gis.domain.GisDevelopProject;
import com.ycd.gis.service.IGisDevelopProjectService;
import com.ycd.common.core.controller.BaseController;
import com.ycd.common.core.domain.AjaxResult;
import com.ycd.common.utils.poi.ExcelUtil;
import com.ycd.common.core.page.TableDataInfo;

/**
 * developprojectController
 * 
 * @author ruoyi
 * @date 2021-11-25
 */
@Controller
@RequestMapping("/gis/developproject")
public class GisDevelopProjectController extends BaseController
{
    private String prefix = "gis/developproject";

    @Autowired
    private IGisDevelopProjectService gisDevelopProjectService;
    @Autowired
    private ISysUserService iSysUserService;

    @RequiresPermissions("gis:developproject:view")
    @GetMapping()
    public String developproject()
    {
        return prefix + "/developproject";
    }

    /**
     * 查询developproject列表
     */
    @RequiresPermissions("gis:developproject:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GisDevelopProject gisDevelopProject)
    {
        startPage();
        List<GisDevelopProject> list = gisDevelopProjectService.selectGisDevelopProjectList(gisDevelopProject);
        return getDataTable(list);
    }

    @PostMapping("/list/{userId}")
    @ResponseBody
    public TableDataInfo list(GisDevelopProject gisDevelopProject,@PathVariable Long userId)
    {
        startPage();
        gisDevelopProject.setUserId(userId);
        List<GisDevelopProject> list = gisDevelopProjectService.selectGisDevelopProjectList(gisDevelopProject);
        return getDataTable(list);
    }


    /**
     * 导出developproject列表
     */
    @RequiresPermissions("gis:developproject:export")
    @Log(title = "developproject", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GisDevelopProject gisDevelopProject)
    {
        List<GisDevelopProject> list = gisDevelopProjectService.selectGisDevelopProjectList(gisDevelopProject);
        ExcelUtil<GisDevelopProject> util = new ExcelUtil<GisDevelopProject>(GisDevelopProject.class);
        return util.exportExcel(list, "developproject数据");
    }

    /**
     * 新增developproject
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存developproject
     */
//    @RequiresPermissions("gis:developproject:add")
    @Log(title = "developproject", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GisDevelopProject gisDevelopProject)
    {
        /*根据userId查User*/
        SysUser sysUser = iSysUserService.selectUserById(gisDevelopProject.getUserId());
        if (sysUser != null){
            //成功
            return toAjax(gisDevelopProjectService.insertGisDevelopProject(gisDevelopProject));
        }
        //出错
        return toAjax(0);
    }

    /**
     * 修改developproject
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        GisDevelopProject gisDevelopProject = gisDevelopProjectService.selectGisDevelopProjectById(id);
        mmap.put("gisDevelopProject", gisDevelopProject);
        return prefix + "/edit";
    }

    /**
     * 修改保存developproject
     */
//    @RequiresPermissions("gis:developproject:edit")
    @Log(title = "developproject", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GisDevelopProject gisDevelopProject)
    {
        /*根据userId查User*/
        SysUser sysUser = iSysUserService.selectUserById(gisDevelopProject.getUserId());
        if (sysUser != null){
            //成功
            return toAjax(gisDevelopProjectService.updateGisDevelopProject(gisDevelopProject));
        }
        //出错
        return toAjax(0);

    }

    /**
     * 删除developproject
     */
//    @RequiresPermissions("gis:developproject:remove")
    @Log(title = "developproject", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gisDevelopProjectService.deleteGisDevelopProjectByIds(ids));
    }
}
